package com.zker.missyou.api.v1;


import com.zker.missyou.dto.PersonDTO;
import com.zker.missyou.model.Banner;
import com.zker.missyou.service.BannerService;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/banner")
@Validated  // 开启校验
public class BannerController {

//    @Autowired
//    private ISkill iSkill;

    @Autowired
    private BannerService bannerService;

    @GetMapping("/name/{name}")
    public Banner getName(@PathVariable String name) {
        Banner banner =  bannerService.getByName(name);
        return banner;
    }

    @PostMapping("/test/{id}")
    //@max(10)注解是配合@Validated使用，校验参数的
    public PersonDTO test(@PathVariable @Range(min = 2, max = 10, message = "不在范围内") Integer id,
                          @RequestParam String name,
                          @RequestBody @Validated PersonDTO person) {
//        iSkill.r();
        PersonDTO dto = PersonDTO.builder()
                .name("zker")
                .age(18)
                .build();
        return dto;

    }

}
